<template>
  <el-row>
    <el-col :span="12">
      <el-form-item :label="$t('基金认缴规模') + $t('金额单位')" prop="subscribeScale">
        <Money v-model="bfForm.subscribeScale" unit="w" :placeholder="$t('基金认缴规模')" />
      </el-form-item>
    </el-col>
    <el-col :span="12">
      <el-form-item :label="$t('基金实缴规模') + $t('金额单位')" prop="paidInScale">
        <Money v-model="bfForm.paidInScale" unit="w" :placeholder="$t('基金实缴规模')" />
      </el-form-item>
    </el-col>
    <el-col :span="12">
      <el-form-item :label="$t('基金投资类型')">
        <el-select v-model="bfForm.investType" :placeholder="$t('请选择')">
          <el-option
            v-for="dict in fundInvestTypeOptions"
            :key="dict.dictValue"
            :label="$t(dict.dictLabel)"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
    </el-col>
    <el-col :span="12">
      <el-form-item :label="$t('基金类型')" prop="bfBase.fundType">
        <el-select v-model="bfForm.fundType" :placeholder="$t('请选择')">
          <el-option
            v-for="dict in fundTypeOptions"
            :key="dict.dictValue"
            :label="$t(dict.dictLabel)"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
    </el-col>
    <el-col :span="12">
      <el-form-item :label="$t('基金期限')" prop="fundTerm">
        <el-input v-model="bfForm.fundTerm" :placeholder="$t('基金期限')" show-word-limit maxlength="50" />
      </el-form-item>
    </el-col>
    <el-col :span="12">
      <el-form-item :label="$t('基金阶段')" prop="fundStage">
        <el-select v-model="bfForm.fundStage" :placeholder="$t('请选择')">
          <el-option
            v-for="dict in fundPhaseOptions"
            :key="dict.dictValue"
            :label="$t(dict.dictLabel)"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
    </el-col>
    <el-col :span="12">
      <el-form-item :label="$t('基金注册成立日')" prop="fundSetTime">
        <DatePicker v-model="bfForm.fundSetTime" :placeholder="$t('基金注册成立日')" />
      </el-form-item>
    </el-col>
    <el-col :span="12">
      <el-form-item :label="$t('管理公司')" prop="bfBase.manageCompanyName">
        <el-autocomplete
          v-model="bfForm.manageCompanyName"
          class="inline-input"
          :fetch-suggestions="companyQuerySearch"
          :placeholder="$t('管理公司')"
          :trigger-on-focus="false"
          :maxlength="100"
          @select="companyHandleSelect"
        />
      </el-form-item>
    </el-col>
    <el-col :span="12">
      <el-form-item :label="$t('管理公司认缴比例(%)')" prop="manageSubscribeRatio">
        <Ratio
          v-model="bfForm.manageSubscribeRatio"
          :precision="4"
          :controls="false"
          :min="0"
          :max="100"
          :placeholder="$t('管理公司认缴比例(%)')"
        />
      </el-form-item>
    </el-col>
    <el-col :span="12">
      <el-form-item :label="$t('基金编码')" prop="fundNumber">
        <el-input v-model="bfForm.fundNumber" :placeholder="$t('基金编码')" show-word-limit :maxlength="30" />
      </el-form-item>
    </el-col>
    <el-col :span="bfForm.isReverseInvestment === 'Y' ? 12 : 24">
      <el-form-item :label="$t('是否有返投')">
        <el-radio-group v-model="bfForm.isReverseInvestment">
          <el-radio
            v-for="dict in isReverseInvestmentOptions"
            :key="dict.dictValue"
            :label="dict.dictValue"
          >{{ $t(dict.dictLabel) }}
          </el-radio>
        </el-radio-group>
      </el-form-item>
    </el-col>
    <el-col v-if="bfForm.isReverseInvestment === 'Y'" :span="12">
      <el-form-item :label="$t('目标返投金额') + $t('金额单位')" prop="targetReverseInvestmentAmount">
        <Money v-model="bfForm.targetReverseInvestmentAmount" unit="w" :placeholder="$t('目标返投金额')" />
      </el-form-item>
    </el-col>
    <el-col v-if="bfForm.isReverseInvestment === 'Y'" :span="24">
      <el-form-item :label="$t('返投标准')" prop="reverseInvestmentStandard">
        <el-input v-model="bfForm.reverseInvestmentStandard" type="textarea" :placeholder="$t('返投标准')" show-word-limit :maxlength="2000" />
      </el-form-item>
    </el-col>
  </el-row>
</template>

<script>

import { gpListByName } from '@/api/fund/gp/gpBase'

export default {
  name: 'BfBaseForm',
  props: {
    // form
    bfForm: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      // 基金类型字典
      fundTypeOptions: [],
      // 基金投资类型
      fundInvestTypeOptions: [],
      // 基金阶段
      fundPhaseOptions: [],
      // 是否有返投
      isReverseInvestmentOptions: [],
      // 天眼查查询参数
      tycParam: {
        id: '',
        name: ''
      },
      // 查询名称参数
      queryParams: {
        name: '',
        shortName: ''
      }
    }
  },
  mounted() {
    this.$bus.$emit('async_done')
  },
  created() {
    // 基金阶段字典
    this.getDicts('fund_phase').then(response => {
      this.fundPhaseOptions = response.data
    })
    // 基金性质字典
    this.getDicts('fund_nature').then(response => {
      this.fundNatureOptions = response.data
    })
    // 基金类型字典
    this.getDicts('fund_type').then(response => {
      this.fundTypeOptions = response.data
    })
    // 基金投资类型
    this.getDicts('fund_invest_type').then(response => {
      this.fundInvestTypeOptions = response.data
    })
    // 是否有返投
    this.getDicts('sys_yes_no').then(response => {
      this.isReverseInvestmentOptions = response.data
    })
  },
  methods: {
    // 标的公司查询
    companyQuerySearch(queryString, cb) {
      queryString = this.isEmpty(queryString) ? '' : queryString
      if (queryString.includes('%')) {
        this.msgError(this.$t('名称存在非法字符'))
      } else {
        gpListByName(queryString).then(res => {
          if (res.code === 200) {
            cb(res.data)
            // const item = { name: this.bfForm.manageCompanyName, shortName: this.bfForm.manageCompanyAlias }
            // this.companyHandleSelect(item)
          }
        })
      }
    },
    // 标的公司选择后事件
    companyHandleSelect(item) {
      // GP名称
      this.bfForm.manageCompanyName = item.value
      // GP简称
      this.bfForm.manageCompanyAlias = item.shortName
    }
  }

}
</script>
